<template>
	<view class="nav-box" :style="{ paddingTop: phoneHeight, background: backgroundColor }">
		<view class="nav-box-back">{{weatherTxt}}</view>
		<text class="nav-box-title" :style="{ color: textColor }">{{
		    titleName
		  }}</text>
	</view>
</template>
<script>
	import {
		FRONT
	} from "../utils/constant.js";
	var amapFile = require('../utils/amap-wx.130.js')
	export default {
		props: {
			/** 标题 */
			titleName: {
				type: String,
				default () {
					return "";
				},
			},
			/** 是否可以返回：不返回时隐藏按钮 */
			isCanBack: {
				type: Boolean,
				default () {
					return false;
				},
			},
			/** 背景颜色 */
			backgroundColor: {
				type: String,
				default () {
					return "#fff";
				},
			},
			/** 返回上一页的参数 */
			urlType: {
				type: String,
				default () {
					return "";
				},
			},
			/** 标题颜色 */
			textColor: {
				type: String,
				default () {
					return "#666";
				},
			},
		},
		data() {
			return {
				phoneHeight: "", //这里在进行调用
				weatherTxt: ''
			};
		},
		onReady() {
			this.getPhoneHeight();
			this.getWeather()
		},
		methods: {
			/**
			 * 获取导航栏高度
			 */
			getPhoneHeight() {
				let that = this;
				uni.getSystemInfo({
					success: function(res) {
						// console.log('getPhoneHeight', res);
						that.phoneHeight = `${res.statusBarHeight}px`;
					},
				});
			},
			getWeather() {
				let that = this
				var myAmapFun = new amapFile.AMapWX({
					key: 'df436f05cea4704b8ceb44a890104987'
				})
				myAmapFun.getWeather({
					city: '石家庄',
					success: function(data) {
						//成功回调
						console.log('获取成功了', data)
						that.weatherTxt = data.weather.data
					},
					fail: function(info) {
						//失败回调
						console.log(info)
					}
				})
			}
		},
	};
</script>
<style lang="scss" scoped>
	.nav-box {
		position: relative;
		background: #ffffff;
		height: 96rpx;
		width: 100vw;
		padding-left: 40rpx;
		display: flex;
		align-items: center;
		padding-left: 16rpx;
		border-bottom: 1rpx solid #ccc;

		.nav-box-back {
			width: 100rpx;
			height: 96rpx;
		}

		.nav-box-title {
			position: absolute;
			left: 0;
			right: 0;
			margin: auto;
			text-align: center;
			height: 96rpx;
			line-height: 96rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			color: #ffffff;
			width: calc(100% - 90rpx);
		}
	}
</style>